import 'dart:convert';

import 'package:example/app/data/model/login_bean.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base_framework/flutter_base_framework.dart';

class LocalLoginModelRepository {
  static final String keyLoginModel = 'key_login_model';

  static saveLoginModel(LoginBean bean) {
    StorageManager.localStorage.setItem(keyLoginModel, jsonEncode(bean.toJson()));
  }

  static deleteLoginModel() {
    StorageManager.localStorage.deleteItem(keyLoginModel);
  }

  static LoginBean? getLoginModel() {
    try {
      var json = StorageManager.localStorage.getItem(keyLoginModel);
      return LoginBean.fromJson(jsonDecode(json));
    } catch (e) {
      debugPrint(e.toString());
      return null;
    }
  }
}